<!--
 * @Description: 其他物料
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-04-27 20:45:54
 * @FilePath: /yuxiuproweb/src/views/material/other/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="品名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入品名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:material:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['md:material:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['md:material:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="materialList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="品名"
        align="center"
        prop="name"
        min-width="150"
      />
      <el-table-column
        label="销售型号"
        align="center"
        prop="salesModel"
        min-width="130"
      />
      <el-table-column
        label="销售别名"
        align="center"
        prop="salesAlias"
        min-width="130"
      />
      <el-table-column label="标签" align="center" prop="label">
        <template slot-scope="{ row }">
          {{ getTypeName(dict.type.md_other_material_label, row.label) }}
        </template>
      </el-table-column>
      <el-table-column label="单位名称" align="center" prop="unitName">
        <template slot-scope="{ row }">
          {{ getTypeName(dict.type.md_other_material_unit_name, row.unitName) }}
        </template>
      </el-table-column>
      <el-table-column label="单重" align="center" prop="pieceWeight" />
      <el-table-column label="是否可用" align="center" prop="isEnable">
        <template slot-scope="{ row }">{{
          row.isEnable === "Y" ? "是" : "否"
        }}</template>
      </el-table-column>
      <el-table-column label="实物高度" align="center" prop="height" />
      <el-table-column label="相关信息" align="center" prop="info" />
      <el-table-column label="是否备货" align="center" prop="stock">
        <template slot-scope="{ row }">{{
          row.stock === "Y" ? "是" : "否"
        }}</template>
      </el-table-column>
      <el-table-column label="最小库存" align="center" prop="minimumBalance" />
      <el-table-column
        label="采购方式 "
        align="center"
        prop="procurementMethod"
      >
        <template slot-scope="{ row }">
          {{ getTypeName(ProcurementMethods, row.procurementMethod) }}
        </template>
      </el-table-column>
      <el-table-column label="库存类型" align="center" prop="stockType">
        <template slot-scope="{ row }">
          {{ getTypeName(StockTypes, row.stockType) }}
        </template>
      </el-table-column>
      <el-table-column label="出库方式 " align="center" prop="deliveryMode">
        <template slot-scope="{ row }">
          {{ getTypeName(DeliveryModes, row.deliveryMode) }}
        </template>
      </el-table-column>
      <el-table-column label="默认仓库" align="center" prop="defaultWarehouse">
        <template slot-scope="{ row }">
          {{ getTypeName(DefaultWarehouses, row.defaultWarehouse) }}
        </template>
      </el-table-column>
      <el-table-column label="出厂价" align="center" prop="factoryPrice" />
      <el-table-column label="经销价" align="center" prop="wholesalePrice" />
      <el-table-column label="零售价" align="center" prop="retailPrice" />
      <el-table-column
        label="操作"
        align="center"
        min-width="130"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:material:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:material:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改其他物料对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList()"
    ></add-view>
  </div>
</template>

<script>
import { listMaterial, delMaterial } from "@/api/material/other";
import {
  ProcurementMethods,
  StockTypes,
  DeliveryModes,
  DefaultWarehouses,
} from "./configure";
import AddView from "./mods/add.vue";
import commonMix from "@/utils/mixins/common";

export default {
  mixins: [commonMix],
  components: {
    AddView,
  },
  dicts: ["md_other_material_label", "md_other_material_unit_name"],
  data() {
    return {
      ProcurementMethods,
      StockTypes,
      DeliveryModes,
      DefaultWarehouses,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 其他物料表格数据
      materialList: [],
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        name: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询其他物料列表 */
    getList() {
      this.loading = true;
      listMaterial(this.queryParams).then((response) => {
        this.materialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.otherMaterialId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = {
        show: true,
        type: "add",
        data: null,
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = {
        show: true,
        type: "edit",
        data: {
          ...row,
        },
      };
      //   this.reset();
      //   const otherMaterialId = row.otherMaterialId || this.ids;
      //   getMaterial(otherMaterialId).then((response) => {
      //     this.form = response.data;
      //     this.open = true;
      //     this.title = "修改其他物料";
      //   });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const otherMaterialIds = row.otherMaterialId || this.ids;
      this.$modal
        .confirm(
          '是否确认删除其他物料编号为"' + otherMaterialIds + '"的数据项？'
        )
        .then(function () {
          return delMaterial(otherMaterialIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "md/material/export",
        {
          ...this.queryParams,
        },
        `material_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
